#!/usr/bin/env node

//console.log(111)

const inquirer = require('inquirer')
const path = require('path')
const fs = require('fs')
const ejs = require('ejs')

inquirer.prompt([
    { type: 'input', name: 'prjName', message: '输入项目名：' }
]).then(res => {
    //console.log(res.prjName)
    const tmplDir = path.join(__dirname, 'templates')
    const destDir = process.cwd()
    fs.readdir(tmplDir, (err, files) => {
        files.forEach(file => {
            //console.log('file',file)
            ejs.renderFile(path.join(tmplDir, file), res, (err, final) => {
                if (err) throw err
                //console.log('final',final)
                //console.log(path.join(destDir, file))
                fs.writeFileSync(path.join(destDir, file), final)
            })
        })
    })
})